package com.gomore.opple.module.login;

import android.content.Intent;
import android.view.KeyEvent;

import com.gomore.opple.R;
import com.gomore.opple.module.BaseActivity;

import javax.inject.Inject;

/**
 * Created by asus on 2017/5/9.
 */
public class LoginActivity extends BaseActivity {
    @Inject
    LoginPresenter mLoginPresenter;

    private LoginFragment loginFragment;

    @Override
    protected void initalizeViews() {
        if (loginFragment == null) {
            loginFragment = LoginFragment.getInstance();
            replaceFragment(loginFragment, false, "login_view");
        }
    }

    @Override
    protected void initializeDependencyInjector() {
        DaggerLoginComponent.builder()
                .dataRepositoryComponent(getRepositoryComponent())
                .loginPresenterModule((new LoginPresenterModule(loginFragment)))
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutView() {
        return R.layout.activity_login;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            Intent mIntent = new Intent();
            mIntent.setAction(Intent.ACTION_MAIN);
            mIntent.addCategory(Intent.CATEGORY_HOME);
            startActivity(mIntent);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
